#define _CRT_SECURE_NO_WARNINGS 1


#include<string>
#include<iostream>

using namespace std;

int lengthOfLastWord(string s)
{
	int left = 0, right = s.size() - 1;
	while (s[right] == ' ')
	{
		right--;
	}
	while (1)
	{
		left = right;
		while (left >= 0 && s[left] != ' ')
		{
			left--;
		}
		return right - left;
	}
}

int main()
{
	string s = "   fly me   to   the moon  ";
	cout << lengthOfLastWord(s) << endl;

	return 0;
}